%% Licensed to the Apache Software Foundation (ASF) under one
%% or more contributor license agreements.  See the NOTICE file
%% distributed with this work for additional information
%% regarding copyright ownership.  The ASF licenses this file
%% to you under the Apache License, Version 2.0 (the
%% "License"); you may not use this file except in compliance
%% with the License.  You may obtain a copy of the License at
%%
%%   http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing,
%% software distributed under the License is distributed on an
%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
%% KIND, either express or implied.  See the License for the
%% specific language governing permissions and limitations
%% under the License.

sequenceDiagram
    Fork -->> Airflow Repo: Start Pull Request
    Note over CI Build: pull_request<br>[Read Token]
    Note over Build Images: pull_request_target<br>[Write Token]
    activate Airflow Repo
    Airflow Repo -->> CI Build: Trigger 'pull_request' event
    activate CI Build
    activate Build Images
    Airflow Repo -->> Build Images: Trigger 'pull_request_target' event
    opt Failed builds
        Note right of Build Images: Find failed<br>[CI Build]
        Build Images -->> CI Build: Cancel
    end
    Note over Build Images: Build info
    par 3.6, 3.7, 3.8
        Note over Build Images: Build PROD Images<br>[COMMIT_SHA]
    and
        Note over Build Images: Build CI Images<br>[COMMIT_SHA]
    end
    par No CI image
        Note over CI Build: Build info
    and
        Note over CI Build: Should trigger tests?
    and
        Note over CI Build: Helm tests
    and
        Note over CI Build: OpenAPI client gen
    end
    par 3.6, 3.7, 3.8
        Build Images ->> GitHub Registry: Push CI Images
        activate GitHub Registry
    and
        Build Images ->> GitHub Registry: Push PROD Images
    end
    opt If any step failed
        Build Images -->> CI Build: Cancel associated run
    end
    deactivate Build Images
    Note over GitHub Registry: Tagged Images<br>[COMMIT_SHA]
    loop Wait for images
        par 3.6, 3.7, 3.8
            CI Build ->> CI Build: Pull CI Images
            Note over CI Build: Wait for<br>[COMMIT_SHA]
        and
            CI Build ->> CI Build: Pull PROD Images
            Note over CI Build: Wait for<br>[COMMIT_SHA]
        end
    end
    par 3.6, 3.7, 3.8
        GitHub Registry ->> CI Build: Pull CI Images
    and
        GitHub Registry ->> CI Build: Pull PROD Images
    end
    deactivate GitHub Registry
    par 3.6, 3.7, 3.8
        Note over CI Build: Run static checks
    and
        Note over CI Build: Build docs
    and
        Note over CI Build: Spell check docs
    and
        opt Triggered?
            Note over CI Build: Tests
        end
    and
        opt Triggered?
            Note over CI Build: Kubernetes  Tests
        end
    end
    Note over CI Build: Quarantined tests
    Note over CI Build: Merge Coverage
    CI Build -->> Coverage.io: Upload Coverage
    CI Build -->> Airflow Repo: Status Check for CI Build
    deactivate Airflow Repo
    deactivate CI Build
